package empox.pos.update;

import java.util.ArrayList;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ProjectUpdateAdapter 
extends BaseAdapter{
	
	Context con;
	ArrayList<String> version;
	ArrayList<String> apkname;
	ArrayList<String> apkVersion;
	ArrayList<Boolean> bl;
	
	public ProjectUpdateAdapter(Context con) {
		this.con = con;
	}
	
	public void setValue(ArrayList<Boolean> isupdate,ArrayList<String> apkname,ArrayList<String> apkVersion,ArrayList<String> currentversion)
	{
		bl = isupdate;
		this.apkname = apkname;
		this.apkVersion = apkVersion;
		version = currentversion;
	}
	
	public void setValue(ArrayList<Boolean> isupdate)
	{
		bl = isupdate;
	}

	public int getCount() {
		if(version != null)
			return version.size();
		else
			return 0;
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}
	
	static class SH
	{
		CheckBox cb;
		TextView tv1;
		TextView tv2;
		TextView tv3;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		SH sh = new SH();

		if (convertView == null) {
			convertView = new LinearLayout(con);
			((LinearLayout) convertView).setGravity(Gravity.CENTER);

			sh.cb = new CheckBox(con);
			sh.cb.setFocusable(false);
			sh.cb.setEnabled(false);
			sh.cb.setWidth(100);
			sh.cb.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.cb);
			
			sh.tv1 = new TextView(con);
			sh.tv1.setWidth(200);
			sh.tv1.setHeight(30);
			sh.tv1.setGravity(Gravity.LEFT);
			sh.tv1.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv1);

			sh.tv2 = new TextView(con);
			sh.tv2.setWidth(100);
			sh.tv2.setHeight(30);
			sh.tv2.setGravity(Gravity.CENTER);
			sh.tv2.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv2);


			sh.tv3 = new TextView(con);
			sh.tv3.setWidth(100);
			sh.tv3.setHeight(30);
			sh.tv3.setGravity(Gravity.CENTER);
			sh.tv3.setTextColor(0xff57290a);
			((LinearLayout) convertView).addView(sh.tv3);
			
			convertView.setTag(sh);
		} else {
			sh = (SH) convertView.getTag();
		}


		sh.cb.setChecked(bl.get(position));
		sh.tv1.setText(apkname.get(position));
		sh.tv2.setText(apkVersion.get(position));
		sh.tv3.setText(version.get(position));
		
		return convertView;
	}

}
